export default {

	async updateUserInfo() {

	},
	async getUserInfo() {
		const res = await uni.$H.get('/user/getUserInfo', {}, {
			authCode: true
		})
		if (res.status === 0) {
			let userInfo = uni.$u.deepClone(res.body)
			uni.setStorageSync("phone", userInfo.phone)
			uni.setStorageSync("userId", userInfo.userId)
			uni.setStorageSync("headerUrl", userInfo.headerUrl)
			uni.setStorageSync("userName", userInfo.userName)
			uni.setStorageSync("password", userInfo.password)
			uni.setStorageSync("roleId", userInfo.roleId)
			uni.setStorageSync("wxId", userInfo.wxId)
		} else {
			uni.$showMsg(res.message, "error")
		}
	},
	async login(form) {
		const res = await uni.$H.post('/user/login', form, {
			authCode: false
		})
		if (res.status === 0) {
			uni.setStorageSync('authCode', res.body.authCode)
			uni.setStorageSync("selectedProject", '请选择')
			await this.getUserInfo()
			uni.switchTab({
				url: "/pages/ihome/home/home"
			})
		} else if (res.status === 10002) {
			uni.$showMsg('密码输入错误')
		} else {
			uni.$showMsg(res.message)
		}
	},
	// /user/loginOut
	async loginOut() {
		const res = await uni.$H.get('/user/loginOut', {}, {
			authCode: true
		})
		if (res.status === 0) {
			uni.removeStorageSync('authCode')
			uni.removeStorageSync("phone");
			uni.setStorageSync("userId", "-");
			uni.removeStorageSync("headerUrl");
			uni.setStorageSync("userName", '未登录');
			uni.removeStorageSync("password");
			uni.removeStorageSync('selectedProject')
			uni.removeStorageSync('estateId')
			uni.setStorageSync("roleId", "0");
			uni.removeStorageSync("wxId");
			uni.switchTab({
				url: "/pages/ihome/home/home"
			})
		} else {
			uni.$showMsg(res.message)
		}
	}
}
